package com.sys.gradepaysys.controller.stuServlet;

import com.alibaba.fastjson.JSON;
import com.sys.gradepaysys.dao.BaseDao;
import com.sys.gradepaysys.entity.ResultData;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "updatePwd", value = "/updatePwd")
public class updatePwd extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sid = request.getParameter("sid");
        String newpwd = request.getParameter("newpwd");
        String arr[]={newpwd,sid};
        String sql="update student set password=? where s_id=? ";
        boolean b = BaseDao.DoObject(sql, arr);
        if (b){
            String s = "";
            s = JSON.toJSONString(new ResultData<>(200, "修改成功!", null));
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(s);
        }else {
            String s = "";
            s = JSON.toJSONString(new ResultData<>(200, "修改失败!", null));
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(s);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
